Skip to content

🐛 Fix SequenceSet#slice with valid positive range.begin but invalid negative range.end - #776

Merged
nevans merged 1 commit into
masterfrom
sequence_set/fix-slice-range-pos-to-out-of-range-neg
Oct 10, 2026
Merged

nevans merged 1 commit into
masterfrom
sequence_set/fix-slice-range-pos-to-out-of-range-neg

Conversation

@nevans

@nevans nevans commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

When slicing with a positive..negative range, where the range ends prior to the beginning of the set, SequenceSet#slice incorrectly set max to the last value in the set, without regarding the sign of the range end. This converted both set[first..last] and set[first..-last] into set[first..] when the range end is out of range, which is correct for positive range end, but clearly incorrect for negative range end.

This PR fixes that, by treating a missing negative max as 0, e.g: identical to set[first...0]. Assuming first.abs <= cardinality, this will return an empty set.

@nevans nevans added the bug Something isn't working label Oct 3, 2026
@nevans
nevans added this pull request to stack #775 October 3, 2026 00:33
@nevans nevans added the backport-0.5 This ticket needs to be backported to the v0.5-stable branch. label Oct 3, 2026
@nevans
nevans force-pushed the sequence_set/fix-slice-range-pos-to-out-of-range-neg branch from ada5632 to b546855 Compare October 3, 2026 13:42
@nevans nevans changed the title 🐛 Fix SequenceSet#slice(pos..too_low_neg) 🐛 Fix SequenceSet#[] for range with valid positive begin, but invalid negative end Oct 3, 2026
@nevans nevans changed the title 🐛 Fix SequenceSet#[] for range with valid positive begin, but invalid negative end 🐛 Fix SequenceSet#[] with valid positive range.begin but invalid negative range.end Oct 3, 2026
When slicing with a positive...negative range, where the range ends
prior to the beginning of the set, this incorrectly set `max` to the
_last_ value in the set, without regarding the sign of the range end.
This converts both `set[start..end]` and `set[start..-end]` into
`set[start..]` when the range end is out of range, which is correct for
positive range end, but clearly incorrect for negative range end.
@nevans
nevans force-pushed the sequence_set/fix-slice-range-pos-to-out-of-range-neg branch from b546855 to c92bce6 Compare October 10, 2026 03:15
Base automatically changed from sequence_set/fix-slice-when-start-at-star to master October 10, 2026 03:25
@nevans
nevans merged commit c92bce6 into master Oct 10, 2026
48 of 51 checks passed
@nevans
nevans deleted the sequence_set/fix-slice-range-pos-to-out-of-range-neg branch October 10, 2026 03:25
@nevans nevans changed the title 🐛 Fix SequenceSet#[] with valid positive range.begin but invalid negative range.end 🐛 Fix SequenceSet#slice with valid positive range.begin but invalid negative range.end Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-0.5 This ticket needs to be backported to the v0.5-stable branch. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant